//
//  HYtableViewCellForMyTableViewCell.m
//  TTLestening
//
//  Created by dllo on 16/3/23.
//  Copyright © 2016年 dilo. All rights reserved.
//

#import "HYtableViewCellForMyTableViewCell.h"
#import "HYCollectionCellFlowLayout.h"
#import "ZFDownloadViewController.h"
#define WIDTH [UIScreen mainScreen].bounds.size.width

@interface HYtableViewCellForMyTableViewCell () <UICollectionViewDataSource, UICollectionViewDelegate>

@property (nonatomic, strong)  UILabel *labelForUser;
@property (nonatomic, strong)  UILabel *labelForSubtitle;
@property (nonatomic, strong)  UILabel *labelForHeaderName;
@property (nonatomic, retain) UICollectionViewFlowLayout *flowLayout;
@property (nonatomic, retain) UICollectionView *collection;

@end

@implementation HYtableViewCellForMyTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self) {

        [self createSubViews];

    }
    return self;
}


- (void)createSubViews {
    
    [self createFlowLayout];
    
    self.collection = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, self.contentView.frame.size.width, self.contentView.frame.size.height) collectionViewLayout:self.flowLayout];
    
    self.collection.backgroundColor = [UIColor whiteColor];
    [self.contentView addSubview:self.collection];
    
    self.collection.scrollEnabled = NO;
    
    self.collection.dataSource = self;
    self.collection.delegate = self;
    UINib *nib = [UINib nibWithNibName:@"HYCollectionCellFlowLayout" bundle:[NSBundle mainBundle]];
    [self.collection registerNib:nib forCellWithReuseIdentifier:@"pool"];
    
    }

- (void)createFlowLayout {
    
    self.flowLayout = [[UICollectionViewFlowLayout alloc] init];
    self.flowLayout.sectionInset = UIEdgeInsetsMake(10, 10, 10, 10);
    
    self.flowLayout.minimumInteritemSpacing = 10;
    self.flowLayout.minimumLineSpacing = 10;
    
}


- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    

    return 4;
    
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    NSArray *arr = @[@"   本地音乐",@"   歌曲下载",@"   MV下载",@"   最近播放"].mutableCopy;
    NSArray *arrtubiao = @[@"ttpodicon",@"xiazaigequ",@"iconfont-ttpodicon-4",@"zuijinbofang"].mutableCopy;
    NSArray *arrbackimage = @[@"11.jpg",@"22.jpg",@"33.jpg",@"44.jpg"].mutableCopy;
    
    HYCollectionCellFlowLayout *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"pool" forIndexPath:indexPath];
    
    cell.title.text = [arr objectAtIndex:indexPath.row];
    cell.imagetubiao.image = [UIImage imageNamed:[arrtubiao objectAtIndex:indexPath.row]];
    
    cell.backimage.image = [UIImage imageNamed:[arrbackimage objectAtIndex:indexPath.row]];
    
    return cell;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    ZFDownloadViewController *down = [[ZFDownloadViewController alloc] init];
    //[self.navi pushViewController:down animated:NO];

    // 获取该视图层最下边的VC.
    id object = [self nextResponder];
    while (![object isKindOfClass:[UIViewController class]] &&
           object != nil) {
        object = [object nextResponder];
    }
    
    UIViewController *vc = (UIViewController*)object;
    // VideoPlayerVC 是被推出的VC.
    //VideoPlayerVC *player = [[VideoPlayerVC alloc] init];
    [vc.navigationController pushViewController:down animated:YES];

}

- (void)layoutSubviews {
    
    [super layoutSubviews];
    
    self.collection.frame = self.contentView.frame;
    self.flowLayout.itemSize = CGSizeMake((WIDTH - 30) * 0.5,(WIDTH - 30) * 0.5 * 0.56);
    
}


- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
